<template>
  <div class="product-grid">
    <div class="product-card" v-for="product in products" :key="product.id">
      <div class="new-tag" v-if="product.new">{{type=='new'?'新品':'热销'}}</div>
      <div class="image-container" @mouseenter="showIcons = product.id" @mouseleave="showIcons = null">
        <img :src="product.image" :alt="product.name">
        <div class="action-icons" v-show="showIcons === product.id">
          <div class="icon-group">
<!--            <button class="icon-btn" title="收藏">-->
<!--              <i class="heart-icon"></i>-->
<!--            </button>-->
            <button class="icon-btn" title="快速查看" @click="$router.push({path: '/prductDetail', query: {id: product.id}})">
              <i class="search-icon"></i>
            </button>
            <button class="icon-btn" title="加入购物车"  @click="$router.push({path: '/prductDetail', query: {id: product.id}})">
              <i class="cart-icon"></i>
            </button>
          </div>
        </div>
      </div>
      <div class="product-info">
        <h3 class="product-name">{{ product.name }}</h3>
        <div class="rating">
          <span class="stars">
            <i v-for="n in 5" :key="n"
               class="star"
               :class="{ 'filled': n <= product.rating }">
              ★
            </i>
          </span>
          <span class="review-count">({{ product.rating }})</span>
        </div>
        <div class="price">
          <span class="original-price">${{ product.originalPrice }}</span>
          <span class="current-price">${{ product.currentPrice }}元</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ProductCard',
  props: {
    products:Array,
    type:String
  },
  created() {
    // console.log(this.type)
  },
  data() {
    return {
      showIcons: null,

    }
  }
}
</script>

<style scoped>
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 30px;
  padding: 30px;
  background-color: #f8f9fa;
}

.product-card {
  position: relative;
  background: white;
  border: none;
  border-radius: 12px;
  padding: 20px;
  transition: all 0.3s ease;
  overflow: hidden;
}

.product-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
}

.new-tag {
  position: absolute;
  top: 15px;
  left: 15px;
  background: #8AB660;
  color: white;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.5px;
  z-index: 2;
  box-shadow: 0 2px 8px rgba(138, 182, 96, 0.3);
}

.image-container {
  position: relative;
  padding-top: 100%;
  border-radius: 8px;
  overflow: hidden;
  background: #f5f5f5;
}

.image-container img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.product-card:hover .image-container img {
  transform: scale(1.05);
}

.action-icons {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -60px;
  background: rgba(255, 255, 255, 0.95);
  padding: 15px;
  transition: bottom 0.3s ease;
}

.product-card:hover .action-icons {
  bottom: 0;
}

.icon-group {
  display: flex;
  justify-content: center;
  gap: 15px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: #8AB660;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(138, 182, 96, 0.2);
}

.icon-btn:hover {
  background: #7aa550;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(138, 182, 96, 0.3);
}

/* 图标样式优化 */
.heart-icon, .search-icon, .cart-icon {
  width: 20px;
  height: 20px;
  position: relative;
  display: inline-block;
}

.heart-icon::before,
.heart-icon::after {
  content: '';
  position: absolute;
  background: white;
  height: 12px;
  width: 7px;
  border-radius: 4px;
}

.heart-icon::before {
  transform: rotate(-45deg);
  left: 6px;
}

.heart-icon::after {
  transform: rotate(45deg);
  left: 13px;
}

.search-icon {
  border: 2.5px solid white;
  border-radius: 50%;
  transform: scale(0.8);
}

.search-icon::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 2.5px;
  background: white;
  bottom: -6px;
  right: -6px;
  transform: rotate(45deg);
}

.cart-icon::before {
  content: '🛒';
  color: white;
  font-size: 18px;
}

.product-info {
  padding-top: 20px;
  text-align: center;
}

.product-name {
  margin: 12px 0;
  font-size: 17px;
  color: #2c3e50;
  font-weight: 600;
}

.rating {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 8px 0;
}

.stars {
  display: flex;
  gap: 2px;
}

.star {
  color: #e0e0e0;
  font-size: 18px;
}

.star.filled {
  color: #ffd700;
}

.review-count {
  color: #7f8c8d;
  font-size: 14px;
}

.price {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.original-price {
  color: #95a5a6;
  text-decoration: line-through;
  font-size: 15px;
}

.current-price {
  color: #8AB660;
  font-weight: 600;
  font-size: 18px;
}

@media (max-width: 768px) {
  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
    padding: 15px;
  }

  .product-card {
    padding: 15px;
  }

  .icon-btn {
    width: 35px;
    height: 35px;
  }

  .product-name {
    font-size: 15px;
  }
}
</style>